package com.lz.sports.bean

import androidx.databinding.ObservableField
import androidx.databinding.ObservableInt

//检录对象
class Inspect(val num: Int) {

    // 0未选中, 1选中, 2重复
    val levelState = ObservableInt(0)

    //考生信息
    val inspectExaminee = ObservableField<ExamInspect>()

    //当前是否是选中项
    var isSelected: Boolean = false

    //清空重置
    fun reset() {
        levelState.set(0)
        inspectExaminee.set(null)
        isSelected = false
    }

    fun unselect() {
        isSelected = false
        if (levelState.get() != 2) levelState.set(0)
    }

    //选中
    fun select() {
        isSelected = true
        if (levelState.get() != 2) levelState.set(1)
    }

    fun joinExamInspect(inspect: ExamInspect) {
        inspectExaminee.set(inspect)
    }

    fun examInspect(): ExamInspect? = inspectExaminee.get()?.also { it.number = num }

    fun examineeName(): String? = inspectExaminee.get()?.examinee?.studentName

    fun examineeNo(): String? = inspectExaminee.get()?.examinee?.examineesNo

    fun hasInspect(inspect: ExamInspect): Boolean = this.inspectExaminee.get()?.examineeId == inspect.examineeId

    fun hasExaminee(examinee: Examinee): Boolean = this.inspectExaminee.get()?.examineeId == examinee.id

    fun hasExaminee(): Boolean = inspectExaminee.get()?.examinee != null
}